//
//  CololView.swift
//  Example
//
//  Created by xx on 2025/3/24.
//

import UIKit
import FastSwiftSDK
class CololView: FastView {
    
    var callBack:FastStrBlock?
    
    var colors:Array<String> = ["#000000","#FF0000","#FFFFFF","#FFCC33", "#FF9900", "#FF6600","#00FFFF", "#0080FF", "#0000FF","#2C3A47", "#1E2A35", "#0F172A","#8B008B", "#FF00FF", "#FF69B4"]
    
    override func setupUI() {
        for i in 0...colors.count-1{
            let x = i%5*60+i%5*10
            let y = i/5*40+i/5*10
            let btn:UIButton = createButton(frame: kFrame(CGFloat(x),CGFloat(y), 60, 40), tag: i, hexValue: colors[i])
            self.addSubview(btn)
        }
    }
    
    // 创建单个按钮的方法
    private func createButton(frame:CGRect,tag:Int,hexValue: String) -> UIButton {
        let button = PublicView.button(title: "", style: .borderColor) { [weak self] in
            if let color = self?.colors[tag]{
                self?.callBack?(color)
            }
        }
        button.frame = frame
        button.tag = tag
        button.backgroundColor = .hex(hexValue as NSString)
        
        return button
    }

}
